package com.example.lvsuo.controller;


import com.example.lvsuo.annotation.Redis;
import com.example.lvsuo.entity.SystemAuthority;
import com.example.lvsuo.entity.vo.SystemAuthorityVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.ISystemAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统权限表 前端控制器
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/systemAuthority")
public class SystemAuthorityController {
    @Autowired
    ISystemAuthorityService ss;

    @Autowired
    RedisTemplate<Object,Object> rt;

    @Redis("systemAuthority")
    @GetMapping
    Result query(String id){
        List<SystemAuthorityVo> list = ss.querySa(id);
        return Result.back(list);
    }

    @DeleteMapping("/delete")
    Result deAuthority(){
        rt.delete("systemAuthority");
        return Result.back("成功");
    }

    /**
     * 查询权限表
     * 获取树形图
     * @return
     */
    @GetMapping(params ={"chaxun=1"})
    public Result getSystemAuthority(){
        List<SystemAuthorityVo> list=ss.getSystemAuthority();
        return Result.back("ok","200",list);
    }

    @GetMapping("/{id}")
    public Result getSystemAuthorityByid(@PathVariable String id){
        String fid = ss.getSystemAuthorityByid(id);
        return Result.back("ok","20000",fid);
    }

    @PutMapping
    public Result updateSystemAuthorityFid(@RequestBody SystemAuthority systemAuthority){
        ss.updateSystemAuthorityFid(systemAuthority);

        return Result.back("ok","20000");
    }

}

